package fzrj.qkl.demo.controller;

import fzrj.qkl.demo.model.CommonResponse;
import fzrj.qkl.demo.service.backend.UserService;
import org.fisco.bcos.sdk.transaction.model.exception.ContractException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    // 注册
    @PostMapping("/add")
    public CommonResponse addUser(@RequestParam String username, @RequestParam String password) {
        boolean res = userService.addUser(username, password);
        if (res) {
            return CommonResponse.ok(res);
        }
        return CommonResponse.fail("1001",new Exception("error"));
    }

    // 验证
    @PostMapping("/check")
    public CommonResponse checkUser(@RequestParam int id, @RequestParam String password) throws ContractException {
        boolean res = userService.checkUser(id, password);
        if (res) {
            return CommonResponse.ok(res);
        }
        return CommonResponse.fail("1001",new Exception("error"));
    }


}